package Chapter4;

//90页程序4.4
class Count{
    private int serialNumber;
    static int counter=0;  //静态变量counter 作为全局变量，计数对象的数量
    public Count(){
        counter++;    //counter将在被调用时自增1
        serialNumber=counter;  //将counter的值赋给serialNumber，视作对象的唯一编号
    }
    public int getSerialNumber(){
        return serialNumber;   //当对象访问该方法时，返回对应的编号值
    }
}
public class UseStatic {
    public static void main(String[] args) {
        System.out.println("当前编号的值是："+Count.counter);
        Count Tom = new Count();
        Count John = new Count();
        System.out.println("tom的编号是："+Tom.getSerialNumber());
        System.out.println("john的编号是："+John.getSerialNumber());
        System.out.println("现在的编号计数到："+Count.counter);
    }
}
